package router

import (
	"net/http"
	"time"

	"gitee.com/xiaoyutab/gatway/model"
	"gitee.com/xiaoyutab/xgotool/https"
	"github.com/gin-gonic/gin"
	wraphh "github.com/turtlemonvh/gin-wraphh"
)

var r *gin.Engine

func RouterExplode() *gin.Engine {
	time.Local = time.FixedZone("CST", 3600*8) // 设置时区为东八区
	if r == nil {
		// 路由加载
		// 调试阶段输出路由相关信息
		// gin.SetMode(gin.ReleaseMode)
		r = gin.Default()
		// 路由格式：
		// <app>/router
		// _ 作为预留APP名称，禁止使用，即APP名称不允许为单独一个_
		app(r.Group("_"))
		// 测试网关服务
		r.Any("www", wraphh.WrapHH(func(h http.Handler) http.Handler {
			u := URL{AppRouter: model.AppRouter{Targets: "[\"https://csapi1.xinfushenghuo.cn/.env\"]"}}
			return https.Gatway(h, &u)
		}))
	}
	// 定时任务路由添加
	cron_regedit()
	// 队列任务路由添加
	nsq_regedit()
	return r
}
